package net.liteheaven.dtimer.misc

import android.content.Context
import android.content.Intent
import android.os.Handler
import android.os.Looper
import android.support.v4.app.JobIntentService
import net.liteheaven.dtimer.XLog

/**
 * Created by LiangYu on 2018/7/30.
 * 简单测试JobIntentService
 */
class MyJobIntentService : JobIntentService() {

    private val handle : Handler = Handler(Looper.getMainLooper())

    companion object {
        private const val JOB_ID = 100

        fun enqueueWork(context: Context, work: Intent) {
            JobIntentService.enqueueWork(context, MyJobIntentService::class.java, JOB_ID, work)
        }
    }

    override fun onHandleWork(intent: Intent) {
        XLog.i("NBService do something...")
        handle.postDelayed({ enqueueWork(applicationContext, intent) }, 1000)
    }
}